<template>
  <div id="main" ref="main"></div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import * as echarts from "echarts";
const main = ref();

onMounted(() => {
  setEcharts();
});
function setEcharts() {
  var myChart = echarts.init(main.value);
  var option = {
    grid: {
      top: "15%",
      left: '5%',
      right: "5%",
      bottom: 40,
      containLabel: true,
    },
    legend: {
      top:"3%",
      left: 0,
      textStyle: {
        color: "#C8EAF9",
      },
    },
    dataZoom: [
      {
        type: "inside",
        start: 0,
        end: 10,
      },
      {
        start: 0,
        end: 10,
      },
    ],
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: [
        "2023-01-14",
        "2023-01-15",
        "2023-01-16",
        "2023-01-17",
        "2023-01-18",
        "2023-01-19",
        "2023-01-20",
      ],
      axisLabel: {
        rotate: 15,
        textStyle: {
          color: "#CBD2D5",
        },
        interval: 0,
        margin: 20,
      },
      axisLine: {
        lineStyle: {
          color: "#CCCCCC",
        },
      },
      axisTick: {
        show: false,
      },
    },
    yAxis: {
      type: "value",
      minInterval: 1,
      axisLabel: {
        textStyle: {
          color: "#CBD2D5",
        },
      },
      splitLine: {
        lineStyle: {
          color: "#222324",
        },
      },
      axisTick: {
        show: false,
      },
      axisLine: {
        show: false,
      },
    },
    series: [
      {
        name: "淘宝",
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: "line",
        smooth: true,
        lineStyle: { color: "#2BCDC4" },
        itemStyle: { opacity: 0 },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "#2BCDC4" },
            { offset: 1, color: "transparent" },
          ]),
        },
      },
    ],
  };

  myChart.setOption(option);
  window.addEventListener("resize", () => myChart.resize());
}
</script>

<style lang="less" scoped>
#main {
  width: 100%;
  height: 100%;
}
</style>
